package com.tongji.housediy.view.components
{
	import com.tongji.housediy.vo.Color;
	
	import flash.display.CapsStyle;
	import flash.display.LineScaleMode;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	import mx.core.UIComponent;

	public class RatioComp extends UIComponent
	{
		public  var msg:Array = new Array();
		
		private var scaleArray:Array = [0.35, 0.45, 0.6, 0.77, 1, 1.3, 1.7, 2.2, 2.86];
		private var ratioArray:Array = [70, 90, 60, 77, 100, 130, 85, 110, 143];
		private var scaleNumArray:Array = [2, 2, 1, 1, 1, 1, 0.5, 0.5, 0.5];
		private var currentIndex:int = 4;
		
		public function RatioComp()
		{
			for (var i:Number = 0; i<4; i++)	
			{
				initialise(i);
			}
			draw(ratioArray[currentIndex]);
		}
		
		public function initialise(i:int):void
		{
			var _msg:TextField = new TextField();
			_msg.text = (i + 1).toString() + ".00m";
			_msg.border = false;
			_msg.background = false;
			_msg.selectable = false;
			_msg.autoSize = TextFieldAutoSize.CENTER;
			msg.push(_msg);
			this.addChild(_msg);
		}
		
		public function changeSize(scaleNum:Number):void
		{
			if (scaleNum != 4)
				currentIndex += scaleNum;
			else
				currentIndex = 4;
			changeText(scaleNumArray[currentIndex]);
			draw(ratioArray[currentIndex]);
		}
		
		public function changeText(scaleNum:Number):void
		{
			msg[0].text = scaleNum.toFixed(2).toString() + "m";
			msg[1].text = (scaleNum * 2).toFixed(2).toString() + "m";
			msg[2].text = (scaleNum * 3).toFixed(2).toString() + "m";
			msg[3].text = (scaleNum * 4).toFixed(2).toString() + "m";
		}
		
		public function draw(ratioComp:Number):void
		{
			var color:Number = 0x000000; 
			this.graphics.clear();
			this.graphics.lineStyle(5, color, 1, false, LineScaleMode.NORMAL, CapsStyle.SQUARE);
			this.graphics.moveTo(0, 0);
			for (var i:Number = 0; i < 4; i++)
			{
				this.graphics.lineTo(ratioComp * (i + 1), 0);
				msg[i].x = ratioComp * (i + 1) - msg[0].width / 2;
				msg[i].y = -25;
				color = ~color;
				this.graphics.lineStyle(5, color, 1, false, LineScaleMode.NORMAL, CapsStyle.SQUARE);
			}
		}
	}
}